import { Inject } from '@midwayjs/core';
import { CoolController, BaseController } from '@cool-midway/core';
import { ClassInfoEntity } from '../../entity/info';
import { ClassInfoService } from '../../service/info';
import { BaseSysUserEntity } from '../../../base/entity/sys/user';
import { DoctorInfoEntity } from '../../../doctor/entity/info';

/**
 * 班级信息
 */
@CoolController({
  api: ['add', 'delete', 'update', 'info', 'list', 'page'],
  entity: ClassInfoEntity,
  service: ClassInfoService,
  pageQueryOp: {
    keyWordLikeFields: ['a.className'],
    fieldEq: ['a.shopId', 'a.doctorId'],
    select: ['a.*', 'b.name as doctorName'],
    join: [
      {
        entity: DoctorInfoEntity,
        alias: 'b',
        condition: 'a.doctorId = b.id',
        type: 'leftJoin',
      },
    ],
    where: ctx => {
      const { startTime, endTime } = ctx.request.body;
      const where = [];
      if (startTime && endTime) {
        where.push([
          'a.startTime BETWEEN :startTime AND :endTime',
          { startTime, endTime },
        ]);
      }
      return where;
    },
  },
})
export class AdminClassController extends BaseController {
  @Inject()
  classInfoService: ClassInfoService;
}
